<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>开通下级代理</title>
    <link rel="stylesheet" href="../../static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/frame/static/css/style.css">
    <link rel="icon" href="../../static/frame/static/image/code.png">
</head>

<body class="body">

    <div class="layui-row layui-col-space10 my-index-main">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">选择级别</label>
                <div class="layui-input-block">
                    <select name="level" id="levallist" onchange="tips()">
                    <option value="0">请选择一个级别</option>
                </select>
                    <div class="layui-form-mid layui-word-aux" id="tips"></div>
                </div>
            </div>


            <div class="layui-form-item">
                <label for="username" class="layui-form-label">代理账号</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="username" id="username" placeholder="">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="pass" class="layui-form-label">代理密码</label>
                <div class="layui-input-block">
                    <input type="password" class="layui-input" name="pass" id="pass" placeholder="">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">代理QQ</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" name="qq" id="qq" placeholder="">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>


        </form>

    </div>
    <script src="../../static/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="../../static/frame/layui/layui.js"></script>
    <script type="text/javascript" src="../../static/js/index.js"></script>
    <script type="text/javascript" src="../../static/frame/echarts/echarts.min.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'element', 'layer', 'vip_tab'], function() {
            $('.my-nav-btn').on('click', function() {
                if ($(this).attr('data-href')) {
                    //vipTab.add('','标题','路径');
                    vipTab.add($(this), '<i class="layui-icon">' + $(this).find("button").html() + '</i>' + $(this).find('p:last-child').html(), $(this).attr('data-href'));
                }
            });

            var form = layui.form;
            var loading = layer.load();
            $.ajax({
                url: '../ajax.php?mod=getbuylist',
                type: 'POST',
                dataType: 'html',
                data: '',
                success: function(data) {
                    layer.close(loading);
                    if (data === '' || data === null) {
                        layer.open({
                            type: 1,
                            title: false,
                            closeBtn: false,
                            area: '300px;',
                            shade: 0.8,
                            id: 'sitenotice',
                            resize: false,
                            btn: ['确定'],
                            btnAlign: 'c',
                            moveType: 1,
                            content: '<div style="padding: 20px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">站长没有添加任何级别</div>',
                            success: function(layero) {}
                        });
                    } else {
                        $('#levallist').html(data);
                        form.render();
                    }
                },
                error: function(data) {
                    layer.close(loading);
                    layer.msg('请求失败' + data);
                }
            })

            form.on('select', function(data) {
                var ii = layer.load(0);

                $.ajax({
                    type: "POST",
                    url: "../ajax.php?mod=addagenttips",
                    data: 'leval=' + data.value,
                    dataType: 'html',
                    success: function(data) {
                        layer.close(ii);
                        $("#tips").html(data);
                    },
                    error: function(data) {
                        layer.close(ii);
                        layer.msg('请求数据失败，建议刷新重试，多次重试不行请与客服联系！');

                    }
                });

            });

            form.on('submit(formDemo)', function(data) {
                var ii = layer.load(0);

                $.ajax({
                    type: "POST",
                    url: "../ajax.php?mod=buyagent",
                    data: 'leval=' + data.field.level + '&username=' + encodeURI(data.field.username) + '&pass=' + encodeURI(data.field.pass) + '&qq=' + encodeURI(data.field.qq),
                    dataType: 'html',
                    success: function(data) {
                        layer.close(ii);
                        layer.alert(data);
                    },
                    error: function(data) {
                        layer.close(ii);
                        layer.msg('请求数据失败，建议刷新重试，多次重试不行请与客服联系！');

                    }
                });
                return false;
            });


        });
    </script>
</body>

</html>